﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Booking_Hotel.BLL;
using Booking_Hotel.DBML;
using System.Web.Security;
using Booking_Hotel.DAL;

namespace Booking_Hotel
{
    public partial class LoaiPhong_KhuyenMai : System.Web.UI.Page
    {
        Supplier_Hotel_LoaiPhong_KhuyenMai entities = new Supplier_Hotel_LoaiPhong_KhuyenMai();
        ThanhBHotelDataContext TBK = new ThanhBHotelDataContext();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["ss_SupplierID"] = 2;
                ShowLoaiPhongKhuyenMai();
            }
        }

        protected void bt_insert_Click(object sender, EventArgs e)
        {
            entities = new Supplier_Hotel_LoaiPhong_KhuyenMai();
            entities.Supplier_Hotel_LoaiPhongID = int.Parse(DDL_TenLoaiPhong.SelectedValue);
            entities.TenKhuyenMai = txt_chude.Text.Trim();
            entities.Description = txt_giakhuyenmai.Text.Trim();
            entities.GiaKhuyenMai = Decimal.Parse(txt_giakhuyenmai.Text.Trim());
            DateTime dtime = DateTime.Parse(txt_thoigianbatdau.Text);
            entities.ThoiGianBatDau = dtime;
            DateTime dtime1 = DateTime.Parse(txt_thoigianketthuc.Text);
            entities.ThoiGianKetThuc = dtime1;
            Supplier_hotel_loaiphong_khuyenmaiDAO sp = new Supplier_hotel_loaiphong_khuyenmaiDAO();
            sp.addSupplier_Hotel_loaiphong_khuyenmai(entities);
            ShowLoaiPhongKhuyenMai();
        }
        protected void ShowLoaiPhongKhuyenMai()
        {
            var phong = from dv in TBK.Supplier_Hotels
                        join shl in TBK.Supplier_Hotel_LoaiPhongs on dv.Supplier_HotelID equals shl.Supplier_HotelID
                        join shk in TBK.Supplier_Hotel_LoaiPhong_KhuyenMais on shl.Supplier_Hotel_LoaiPhongID equals shk.Supplier_Hotel_LoaiPhongID
                        where dv.SupplierID == (int)Session["ss_SupplierID"]
                        select new
                        {
                            Supplier_Hotel_LoaiPhong_KhuyenMaiID = shk.Supplier_Hotel_LoaiPhong_KhuyenMaiID,
                            Supplier_Hotel_LoaiPhongID = shk.Supplier_Hotel_LoaiPhongID,
                            TenLoaiPhong = shl.TenLoaiPhong + "(" + dv.TenKhachSan + ")",
                            TenKHuyenMai = shk.TenKhuyenMai,
                            Description = shk.Description,
                            GiaKhuyenMai = shk.GiaKhuyenMai,
                            ThoiGianBatDau = shk.ThoiGianBatDau,
                            ThoigianKetThuc = shk.ThoiGianKetThuc
                        };
            GridView1.DataSource = phong;
            GridView1.DataBind();

        }

      
    }
}